home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * Simple Sample PowerTalk Application Framework
- *
- * ©1991-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * windowstuff.c -- window class instantiation/dispatching
- *
- * change history:
- *
- * SJF 08/23/93 1.0f1 update to final headers, fix comments
- * SJF 04/21/93 1.0b2 update to b2
- * SJF 03/01/93 1.0b1 added digital signatures
- * SJF 02/09/93 1.0b1 update to b1
- * SJF 10/13/92 1.0d4 update to a11
- * SJF 09/09/92 1.0d3 update to a9
- * SJF 05/07/92 1.0d2 update to a6
- * SJF 11/06/91 1.0d1 initial coding
- *
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __OCESTANDARDMAIL__
- #include <OCEStandardMail.h>
- #endif
-
- #include "const.h"
- #include "mytypes.h"
- #include "globals.h"
- #include "utils.h"
-
- #include "base.window.h"
- #include "draw.window.h"
- #include "draw.mailer.window.h"
-
- #include "windowstuff.h"
-
- /* gets info handle for a window */
-
- WInfoHndl GetWindowInfo(WindowPtr window)
- {
- WInfoHndl theInfo;
-
- if (window==nil)
- return nil;
-
- theInfo = (WInfoHndl) GetWRefCon(window);
- return theInfo;
- }
-
-
- /* sets info handle for a window */
-
- void SetWindowInfo(WindowPtr window,WInfoHndl info)
- {
- if (window==nil) {
- DoError(kInternalError);
- return;
- }
-
- SetWRefCon (window,(long)info);
- }
-
-
- /* gets window kind of a given window */
-
- WindowKind GetWindowKind(WindowPtr window)
- {
- WindowKind wKind;
-
- if (window==nil) {
- DoError(kInternalError);
- return 0;
- }
- wKind = ((WindowPeek)window)->windowKind;
- return wKind;
- }
-
-
- /* sets window kind of a given window */
-
- void SetWindowKind(WindowPtr window,WindowKind wKind)
- {
- if (window==nil) {
- DoError(kInternalError);
- return;
- }
-
- ((WindowPeek)window)->windowKind = wKind;
- }
-
-
- /* checks to see if a window is of a certain type */
-
- Boolean IsWindowType(WindowPtr window,WindowKind type)
- {
- return (type == GetWindowKind(window));
- }
-
-
- /* returns true if it's a window created by the application */
-
- Boolean IsAppWindow(WindowPtr window)
- {
- WindowKind wKind;
-
- if (!window)
- return false;
-
- wKind = GetWindowKind(window);
- return (wKind >= userKind);
- }
-
-
- /* returns true if the window belongs to a DA */
-
- Boolean IsDAWindow(WindowPtr window)
- {
- return (GetWindowKind(window) < 0);
- }
-
-
- /* returns the _real_ frontwindow, not including the AOCE copy window */
-
- WindowPtr MyFrontWindow(void)
- {
- WindowPtr window;
-
- window = FrontWindow();
-
- if (gHasCopyWindow) {
- window = (WindowPtr) (((WindowPeek)window)->nextWindow);
- }
- return window;
- }
-
-
- /* locks the data area of a window */
-
- WInfoPtr BeginWindowAccess(WindowPtr theWindow,char *hState)
- {
- WInfoHndl infoHndl;
-
- infoHndl = GetWindowInfo(theWindow);
- *hState = HGetState((Handle) infoHndl);
- MoveHHi((Handle) infoHndl);
- HLock((Handle) infoHndl);
- return *infoHndl;
- }
-
-
- /* unlocks the data area of a window */
-
- void EndWindowAccess(WindowPtr theWindow,char hState)
- {
- WInfoHndl infoHndl;
-
- infoHndl = GetWindowInfo(theWindow);
- HSetState((Handle) infoHndl,hState);
- }
-
-
- /* makes a window of a given type and returns its window pointer */
-
- WindowPtr MakeWindow(WindowKind windowClass,Rect *wRect,StringPtr title,Boolean visible)
- {
- WindowPtr window,windowLook;
- Rect theRect;
- short expHeight,contHeight,mWidth;
- OSErr err;
- Point offsetWind;
- GrafPtr savePort;
-
- if (wRect==nil)
- {
- if (gHasStandardMail) {
- err = SMPGetDimensions(&mWidth,&contHeight,&expHeight);
- if (err!=noErr)
- DoError(err);
- }
- else mWidth = 492;
- SetRect(&theRect, 20, 50, 20 + mWidth, 340);
-
- GetPort(&savePort);
- windowLook = MyFrontWindow();
- while (windowLook) {
- SetPt(&offsetWind,0,0);
- SetPort(windowLook);
- LocalToGlobal(&offsetWind);
- if (theRect.top==offsetWind.v && theRect.left==offsetWind.h) {
- OffsetRect(&theRect,kWindowOffset,kWindowOffset);
- windowLook = MyFrontWindow();
- }
- else
- windowLook=(WindowPtr)((WindowPeek)windowLook)->nextWindow;
- }
- SetPort(savePort);
-
- } else
- theRect = *wRect;
-
- switch (windowClass) {
- case kBaseWindow:
- window = BaseMakeWindow(&theRect,title,visible,zoomDocProc,true);
- break;
- case kDrawWindow:
- window = DrawMakeWindow(&theRect,title,visible,zoomDocProc,true);
- break;
- case kDrawMailerWindow:
- window = DMailerMakeWindow(&theRect,title,visible,zoomDocProc,true);
- break;
- default:
- DoError(kInternalError);
- }
-
- return window;
- }
-
-
- /* sends a message to a given window */
-
- void *SendWindowMessage(WindowPtr window,short msg,void *data)
- {
- WInfoHndl infoHndl;
- char hState;
- MsgProc callProc;
- void *theMsg;
-
- if (!IsAppWindow(window))
- return nil;
-
- infoHndl = GetWindowInfo(window);
- hState = HGetState((Handle) infoHndl);
- HLock((Handle) infoHndl);
-
- switch (msg) {
- case kIdleMessage:
- callProc = (**infoHndl).m_idle;
- break;
- case kFixCursorMessage:
- callProc = (**infoHndl).m_fixCursor;
- break;
- case kActivateMessage:
- callProc = (**infoHndl).m_activate;
- break;
- case kDeactivateMessage:
- callProc = (**infoHndl).m_deactivate;
- break;
- case kUpdateMessage:
- callProc = (**infoHndl).m_update;
- break;
- case kKeyMessage:
- callProc = (**infoHndl).m_key;
- break;
- case kResizeMessage:
- callProc = (**infoHndl).m_resize;
- break;
- case kClickMessage:
- callProc = (**infoHndl).m_click;
- break;
- case kDestroyMessage:
- callProc = (**infoHndl).m_destroy;
- break;
- case kUndoMessage:
- callProc = (**infoHndl).m_undo;
- break;
- case kCutMessage:
- callProc = (**infoHndl).m_cut;
- break;
- case kCopyMessage:
- callProc = (**infoHndl).m_copy;
- break;
- case kPasteMessage:
- callProc = (**infoHndl).m_paste;
- break;
- case kClearMessage:
- callProc = (**infoHndl).m_clear;
- break;
- case kPrintMessage:
- callProc = (**infoHndl).m_print;
- break;
- case kPageSetupMessage:
- callProc = (**infoHndl).m_pageSetup;
- break;
- case kSaveMessage:
- callProc = (**infoHndl).m_save;
- break;
- case kLoadMessage:
- callProc = (**infoHndl).m_load;
- break;
- case kEventMessage:
- callProc = (**infoHndl).m_event;
- break;
- case kHitControlMessage:
- callProc = (**infoHndl).m_ctrlHit;
- break;
- case kSelectAllMessage:
- callProc = (**infoHndl).m_selectAll;
- break;
- case kGroupMessage:
- callProc = (**infoHndl).m_group;
- break;
- case kUnGroupMessage:
- callProc = (**infoHndl).m_unGroup;
- break;
- default:
- return nil;
- }
-
- if (callProc)
- theMsg = (*callProc)(window,*infoHndl,data);
-
- HSetState((Handle) infoHndl,hState);
- return theMsg;
- }
-
-
-